package com.ys.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.ys.interceptor.LoginInterceptor;

//spring boot 2.0以上版本
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
//		registry.addViewController("/").setViewName("index");
//		registry.addViewController("/login").setViewName("login");
//		registry.addViewController("/main.html").setViewName("dashboard");
	}

	// 注册拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry
			.addInterceptor(new LoginInterceptor())
			.addPathPatterns("/web/inter/**", "/api/inter/**")
			.excludePathPatterns("/login", "/index");
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		System.out.println("path---" + MyConfig.getProfile());
		/** 图片传路径 */
		registry.addResourceHandler("/profile/**").addResourceLocations("file:" + MyConfig.getProfile() + "/");
    }
	
//	// 跨域服务配置
//	@Override
//	public void addCorsMappings(CorsRegistry registry) {
//		//添加映射路径
//		registry.addMapping("/**")
//		.allowedOrigins(CorsConfiguration.ALL)
//		//是否发送Cookie
//		.allowCredentials(true)
//		//放行哪些请求方式
//		.allowedMethods(CorsConfiguration.ALL)
//		//放行哪些原始请求头部信息
//		.allowedHeaders(CorsConfiguration.ALL)
//		.maxAge(3600);
//	}
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//    	System.out.println("path---" +MyConfig.getProfile());
//        /** 图片传路径 */
//        registry.addResourceHandler("/profile/*").addResourceLocations("file:D:/data/upload" + MyConfig.getProfile());
//
//    }
}
